package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.exception.CustomException;
import com.ruoyi.system.mapper.SysBuildUnitMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysBuildHouseMapper;
import com.ruoyi.system.domain.SysBuildHouse;
import com.ruoyi.system.service.ISysBuildHouseService;

/**
 * 房间管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-01-28
 */
@Service
public class SysBuildHouseServiceImpl implements ISysBuildHouseService 
{
    @Autowired
    private SysBuildHouseMapper sysBuildHouseMapper;
    @Autowired
    private SysBuildUnitMapper sysBuildUnitMapper;

    /**
     * 查询房间管理
     * 
     * @param id 房间管理ID
     * @return 房间管理
     */
    @Override
    public SysBuildHouse selectSysBuildHouseById(Long id)
    {
        return sysBuildHouseMapper.selectSysBuildHouseById(id);
    }

    /**
     * 查询房间管理列表
     * 
     * @param sysBuildHouse 房间管理
     * @return 房间管理
     */
    @Override
    public List<SysBuildHouse> selectSysBuildHouseList(SysBuildHouse sysBuildHouse)
    {
        return sysBuildHouseMapper.selectSysBuildHouseList(sysBuildHouse);
    }

    /**
     * 新增房间管理
     * 
     * @param sysBuildHouse 房间管理
     * @return 结果
     */
    @Override
    public int insertSysBuildHouse(SysBuildHouse sysBuildHouse)
    {
        Long unitid = sysBuildHouse.getUnitId();
        if (sysBuildUnitMapper.selectSysBuildUnitById(unitid) == null) {
            throw new CustomException("不存在此单元，请核对");
        }
        return sysBuildHouseMapper.insertSysBuildHouse(sysBuildHouse);
    }

    /**
     * 修改房间管理
     * 
     * @param sysBuildHouse 房间管理
     * @return 结果
     */
    @Override
    public int updateSysBuildHouse(SysBuildHouse sysBuildHouse)
    {
        Long unitid = sysBuildHouse.getUnitId();
        if (sysBuildUnitMapper.selectSysBuildUnitById(unitid) == null) {
            throw new CustomException("不存在此单元，请核对");
        }
        return sysBuildHouseMapper.updateSysBuildHouse(sysBuildHouse);
    }

    /**
     * 批量删除房间管理
     * 
     * @param ids 需要删除的房间管理ID
     * @return 结果
     */
    @Override
    public int deleteSysBuildHouseByIds(Long[] ids)
    {
        return sysBuildHouseMapper.deleteSysBuildHouseByIds(ids);
    }

    /**
     * 删除房间管理信息
     * 
     * @param id 房间管理ID
     * @return 结果
     */
    @Override
    public int deleteSysBuildHouseById(Long id)
    {
        return sysBuildHouseMapper.deleteSysBuildHouseById(id);
    }
}
